
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.util.Calendar;
import javax.persistence.*;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author root
 */
@Entity
public class WeightAndHeight extends AbstractEntity {
    
    @Column(columnDefinition="Decimal(10,2)", nullable=false )
    private float weight;
   
    @Column(columnDefinition="Decimal(10,2)", nullable=false )
    private float height;
    
    @Temporal(TemporalType.DATE)
    @Column(nullable=false)
    private Calendar collectionDate;
    
    //Relationships
    @OneToOne
    @JoinColumn(nullable=false)
    private Campaign campaign;
    
    @OneToOne
    @JoinColumn(nullable=false)
    private Human human;
    
    @Override
    public void generateHash(){
        if ( getId() == null){
            String hash =""
                    + this.getCollectionDate()
                    + ((this.getHuman() != null) ? this.getHuman().getId() : "")
                    + ((this.getCampaign() != null) ? this.getCampaign().getId() :""); 
            this.setId( Long.valueOf( EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public Campaign getCampaign() {
        return campaign;
    }

    public void setCampaign(Campaign campaign) {
        this.campaign = campaign;
    }

    public Calendar getCollectionDate() {
        return collectionDate;
    }

    public void setCollectionDate(Calendar collectionDate) {
        this.collectionDate = collectionDate;
    }

    public float getHeight() {
        return height;
    }

    public void setHeight(float height) {
        this.height = height;
    }

    public Human getHuman() {
        return human;
    }

    public void setHuman(Human human) {
        this.human = human;
    }

    public float getWeight() {
        return weight;
    }

    public void setWeight(float weight) {
        this.weight = weight;
    }

    
}
